#ifndef BACKUP_H
#define BACKUP_H


#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <semaphore.h>

#define MAX_PATH_LENGTH 256
#define MAX_PROCESSES 10
#define BUFFER_SIZE 1024
#define THREAD_COUNT 4
#define FILE_MAX 500 * 1024 * 1024


typedef struct { //备份任务
    char source[MAX_PATH_LENGTH];
    char destination[MAX_PATH_LENGTH];
} BackupTask;

typedef struct { //大文件多线程复制时的传入参数
    FILE* source;
    FILE* dest;
    long start_offset;
    long end_offset;
} ThreadData;

// .h文件声明全局变量，会嵌入到引用该头文件的文件中
extern long long dirSize; //目录下所有文件的字节数
extern long long written; //已经写入的字节数e
extern pthread_mutex_t mutex; //定义互斥锁

long long calculateDirectorySize(const char *path);

int copyPermissions(const char* sourcePath, const char* destinationPath);

void delete_files_in_directory(const char* directory);

void *draw_progress_bar_thread(void *arg);

void *copy_bigfile_thread(void* arg);

void copy_file(const char* source_file, const char* dest_file);

void backup_directory(const char* source, const char* destination);

void* backup_directory_thread(void* arg);



#endif
